<template>
    <div>
        <el-table :data="bannerList" border style="width: 100%">
            <el-table-column prop="id" label="编号" width="180">
            </el-table-column>
            <el-table-column prop="title" label="轮播图标题" width="180">
            </el-table-column>
            <el-table-column prop="img" label="图片">
                <template slot-scope="item">
                    <img v-if="item.row.img" :src="item.row.img" class="img" alt="" srcset="">
                </template>
            </el-table-column>
            <el-table-column prop="status" label="状态">
                <template slot-scope="item">
                    <div>
                        {{ item.row.status == 1 ? '启用' : '禁用' }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="success" size="small" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" size="small" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { bannerDelete, bannerEdit } from '../../request/api';
import { mapGetters, mapActions } from 'vuex';
// import {}
export default {
    data() {
        return {}
    },
    methods: {
        ...mapActions({
            getBannerList: 'banner/getBannerlistAction',
        }),
        // 修改
        edit(id) {
            this.$emit('edit',id)
        },
        // 删除
        del(id) {
            // 询问用户是否要删除
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //调取删除接口
                bannerDelete({ id }).then(res => {
                    if (res.code == 200) {
                        // 删除成功
                        this.$message.success(res.msg);
                        // 重新渲染视图
                        this.getBannerList();
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }
    },
    mounted() {
        this.getBannerList();
    },
    watch: {},
    computed: {
        ...mapGetters({
            bannerList: 'banner/getBannerList'
        })
    },
    filters: {},
    components: {},
}
</script>
<style scoped>
.img {
    width: 80px;
    height: 80px;
}
</style>